<template>
	<view>
		<view style="height:92upx;position:fixed;top:0;background-color:#FFFFFF;width:750upx;z-index:99;">
			<view @click="backto()" style="position:absolute;width:150upx;height:92upx;float:left;line-height:92upx;">
				<text class="iconfont" style="color:#666666;font-size:48upx;">&#xe617;</text>
			</view>
			<view style="text-align:center;height:92upx;line-height:92upx;color:#000000;font-size:34upx;font-weight:700;">我的门店</view>
			<!-- <view @click="apply_agent()" style="width:150upx;height:92upx;float:right;margin-top:-92upx;line-height:92upx;text-align:center;">
				<text class="iconfont" style="color:#999999;font-size:24upx;">申请代理</text>
			</view> -->
		</view>
		<view style="width:750upx;height:92upx;"></view>
		<!-- <view class="row j-sa px-3  font-weight-6" style="border-top:1upx solid #f6f6f6;border-bottom:1upx solid #f6f6f6;">
			
			<block v-for="(item,index) in menu" :key="index">
				<view class="px-1 py-2" @tap="activeTab(index,item.id)" :class="{active_red:active == index}" >
					{{item.title}}
				</view>
			</block>
			
		</view> -->
		<view style="width:700upx;margin:25upx;">
			<view v-if="!flag">
				<block v-for="(item,index) in agentList" :key="index">
					<view class="order_list" @tap="manage(item)">
						<view class="list_l">
							<image :src="baseUrl+item.store_bgimg"></image>
							<view class="list_info">
								<view class="list_title">{{item.store_name}}</view>
								<view class="list_from">
									<text>会员数：{{item.members}}</text>
								</view>
								<view class="list_time">{{item.time}}</view>
							</view>
						</view>
					</view>
				</block>
			</view>
			<view v-if="flag">
				<view style="width:100%;margin: 50rpx 0 100rpx;text-align: center;">
					<image src="../../static/nocontent.png" mode="" style="width: 243rpx;height: 200rpx;"></image>
					<view style="color: #999;">
						暂无内容
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '@/common/lib/request.js'
	export default {
		data() {
			return {
				page:1,
				baseUrl:request.common.baseUrl,
				menu:[
					{title:'门店'},
					{title:'代理'},
					{title:'区域'},
					{title:'市代'}
				],
				active:0,
				agentList:[],
				flag: false
			}
		},
		onLoad:function(){
			uni.setNavigationBarTitle({
			    title: '我的门店'
			});
			uni.request({
			    url: request.common.baseUrl+'/api/agent/myAgent',
			    data: {
					token:uni.getStorageSync('keyToken'),
					agent_type:this.active+1,
					page:this.page
				},
			    header: {
					'Content-Type':'application/json;charset=UTF-8',
					'Content-Type':'application/x-www-form-urlencoded'
			    },
			    success: (res) => {
					console.log(res)
					if(res.data.code==200){
						this.agentList=res.data.data
					}
					if(this.agentList.length == 0){
						this.flag = true
					}else {
						this.flag = false
					}
			    }
			});
		},
		methods: {
			apply_agent(){
				uni.navigateTo({
					url:"/pages/agent/apply"
				})
			},
			backto(){
				uni.navigateBack({
					delta:1
				})
			},
			activeTab(index,id){
				this.active = index;
				this.page=1;
				uni.request({
				    url: request.common.baseUrl+'/api/agent/myAgent',
				    data: {
						token:uni.getStorageSync('keyToken'),
						agent_type:index+1,
						page:this.page
					},
				    header: {
						'Content-Type':'application/json;charset=UTF-8',
						'Content-Type':'application/x-www-form-urlencoded'
				    },
				    success: (res) => {
						this.agentList=[]
						if(res.data.code==200){
							this.agentList=res.data.data
						}
						if(this.agentList.length == 0){
							this.flag = true
						}else {
							this.flag = false
						}
				    }
				});
			},
			manage(item){
				uni.navigateTo({
					url: '/pages/agent/manage?id='+item.id+'&store_name='+item.shop_name+'&store_bgimg='+item.logo+'&address='+item.detail_address+'&store_manage='+item.name+'&tel_phone='+item.phone+'&work_time='+item.work_time+'&agent_type='+item.agent_type
				});
			}
		},
		
		onReachBottom:function(){
			this.page=this.page+1
			uni.request({
			    url: request.common.baseUrl+'/api/agent/myAgent',
			    data: {
					token:uni.getStorageSync('keyToken'),
					agent_type:this.active+1,
			    	page:this.page
			    },
			    header: {
					'Content-Type':'application/json;charset=UTF-8',
					'Content-Type':'application/x-www-form-urlencoded'
			    },
			    success: (res) => {
			        if(res.data.code==200){
						for (var j = 0; j < res.data.data.length; j++) {
							this.agentList.push(res.data.data[j])
						}
					}else{
						uni.showToast({
						    title: '暂无数据',
							icon: 'none',
						    duration: 2000
						});
					}
			    }
			});
		}
	}
</script>

<style>
.active_red{
	border-bottom: 2px solid #ff6101;
}
.order_list{
	border-bottom:1upx solid #f6f6f6;
	width:700upx;
	height:200upx;
}
.list_l{
	float:left;
	margin-top:30upx;
}
.list_l image{
	width:200upx;
	height:120upx;
	float:left;
	margin-left:10upx;
}
.list_info{
	float:left;
	margin-left:20upx;
}
.list_title{
	font-size:28upx;
	color:#666666;
	width:400upx;
	overflow:hidden;
	text-overflow:ellipsis;
	white-space:nowrap;
}
.list_from{
}
.list_from text{
	font-size:24upx;
	color:#999999;
	height:40upx;
	line-height:40upx;
	text-align:center;
}
.list_time{
	font-size:24upx;
	color:#999999;
}
</style>
